#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int numWays(int steps, int arrLen) {
        if (arrLen == 1) return 1;
        int n = min(steps, arrLen - 1);
        vector<int> dp(n + 1);
        dp[0] = 1;
        int mod = 1e9 + 7;
        int* prev = new int[2] {0};
        for (int i = 0; i < steps; i++)
        {
            prev[0] = dp[0];
            dp[0] = (dp[0] + dp[1]) % mod;
            for (int j = 1; j <= n; j++)
            {
                prev[1] = prev[0];
                prev[0] = dp[j];
                dp[j] = (prev[1] + dp[j]) % mod;
                if (j < n) dp[j] = (dp[j] + dp[j + 1]) % mod;
            }
        }
        return dp[0];
    }
};